package org.com.system.user.action;

import java.util.List;

import org.apache.log4j.Logger;
import org.com.system.user.pojo.User;
import org.com.system.user.service.UserService;
import org.com.system.util.model.Action;
import org.com.system.util.model.ActionValues;
import org.com.system.util.utils.DateUtils;
import org.com.system.util.utils.ModelUtils;
import org.com.system.util.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

public class UserAction extends Action<User>{

	private static final long serialVersionUID = 1L;
	private static Logger logger=Logger.getLogger(UserAction.class);
	
	private User user;
	private List<User> users;
	private ActionValues<String,Object> values;//前台传递的参数
	
	@Autowired()
	@Qualifier("userServer")
	public UserService server;
	
	public void init(){
		
	}
	
	/**
	 * 注册用户
	 * @return
	 */
	public String register(){
		User user=(User)ModelUtils.copyFromMap(getValues(), User.class);
		user.setId(UUIDUtils.getUUID());
		server.save(user);
		logger.info("用户注册:"+user.getUserName()+DateUtils.getSystime());
		return SUCCESS;
	}
	
	/**
	 * 用户登陆
	 * @return
	 */
	public String login(){
		User user=server.get(getValues(), User.class);
		getSession().put("user", user);
		logger.info("用户登陆:"+user.getUserName()+DateUtils.getSystime());
		return SUCCESS;
	}
	
	/**
	 * 用户退出
	 * @return
	 */
	public String logout(){
		getSession().remove("user");
		return SUCCESS;
	}
	
	public String get(){
		user=server.get(user.getId(), User.class);
		return SUCCESS;
	}
	
	/**
	 * 查询用户
	 * @return
	 */
	public String list(){
		users=server.list(values, User.class);
		return SUCCESS;
	}
	
	/**
	 * 更新用户
	 * @return
	 */
	public String update(){
		init();
		return SUCCESS;
	}
	
	/**
	 * 删除用户
	 * @return
	 */
	public String delete(){
		init();
		return SUCCESS;
	}
	
	public String authDetail(){
		return SUCCESS;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public ActionValues<String, Object> getValues() {
		return values;
	}

	public void setValues(ActionValues<String, Object> values) {
		this.values = values;
	}
	
}
